package com.exchange.controller.app.kyc;

import com.exchange.interceptor.BaseValidator;
import com.exchange.interceptor.EnumError;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.upload.UploadFile;
import cn.hutool.core.util.StrUtil;


public class KycValidator extends BaseValidator {
    
    protected void validate(Controller c) {
    	setRet(Ret.fail());
    	this.setShortCircuit(true);//短路型验证
    	
    	String url = getActionKey();
    	if (url.equals("/app/kyc/authC1")) {
            validateRequiredString("lastname", "msg", EnumError.LAST_NAME_NULL.getCode());
            validateRequiredString("firstname", "msg", EnumError.FIRST_NAME_NULL.getCode());
            validateRequiredString("country", "msg", EnumError.COUNTRY_NULL.getCode());
            validateRequiredString("idtype", "msg", EnumError.ID_CARD_TYPE_NULL.getCode());
            validateRequiredString("city", "msg", EnumError.ID_CARD_TYPE_NULL.getCode());
            if(StrUtil.equals(c.getPara("idtype"), "身份证")  ) {
            	validateIdCard("idno", "msg", EnumError.CITY_NULL.getCode());
            }
        }
        if (url.equals("/app/kyc/authC2")) {
        	if(c.getFiles().size() != 3) {
        		addError("msg", EnumError.img_count_error.getCode());
        	}
        	for(UploadFile file : c.getFiles()) {
        		if(file.getFile().length() > 1048576L*3) {
        			addError("msg", EnumError.img_too_big.getCode());
        		}
        	}
        }
        
        
        
    }
}
